#ifndef __SLOTHTTPD_CONFIG_FCGI_LOCATION_HPP__
#define __SLOTHTTPD_CONFIG_FCGI_LOCATION_HPP__

#include <slothttpd/types.hpp>
#include <slothttpd/config/configuration.hpp>
#include <slothttpd/config/location/base_location.hpp>
#include <slothttpd/config/fcgi_app.hpp>
#include <slothttpd/config/formatter.hpp>

#include <cstddef>
#include <string>
#include <ostream>

#include <boost/property_tree/ptree.hpp>
#include <boost/range/iterator_range.hpp>

namespace slothttpd {
namespace config {

class fcgi_location :
        public base_location
{
public:
    struct params_type
    {
        params_type(const std::string &n, const std::string &v, base_location& loc);
        
        std::string     name;
        std::string     format_string;
        formatter       value_formatter;
    };
    
    typedef boost::iterator_range<std::vector<params_type>::const_iterator> params_range_t;
    
    fcgi_location(const boost::property_tree::ptree &node, server &s);
    virtual void apply(connection_ptr c);
    params_range_t params_range() const;
    
public:
    fcgi_app_ptr                        app;
    
    config::configuration::buffer_list  fcgi_stdout_buffers;
    config::configuration::buffer_list  fcgi_stderr_buffers;
    std::size_t                         fcgi_output_buffer_size;
    
    std::vector<params_type>            fcgi_params;
};

std::ostream &operator<<(std::ostream &os, const fcgi_location &loc);
std::ostream &operator<<(std::ostream &os, const fcgi_location::params_type &par);

}
}

#endif
